36bfeb5ec06eb1ff87ad06cb264fd7426d540fd8,src/be/ibridge/kettle/job/entry/shell/JobEntryShell.java,JobEntryShell,executeShell,#Result#List#String[]#,368

Before Change


            
            if( Const.getOS().equals( "Windows 95" ) )
            {
                base = new String[] { "command.com", "/C", getFileName() };
            }
            else
            if( Const.getOS().startsWith( "Windows" ) )
            {
                base = new String[] { "cmd.exe", "/C", getFileName() };
            }
            else 
            {
                base = new String[] { getFileName() };
            }
    
            // Construct the arguments...
            if (argFromPrevious && cmdRows!=null)
            {
                ArrayList cmds = new ArrayList();
                
                // Add the base command...
                for (int i=0;i<base.length;i++) cmds.add(base[i]);
    
                // Add the arguments from previous results...
                for (int i=0;i<cmdRows.size();i++) // Normally just one row, but once in a while to remain compatible we have multiple. 
                {
                    Row r = (Row)cmdRows.get(i);
                    for (int j=0;j<r.size();j++)
                    {
                        cmds.add(r.getValue(j).getString());
                    }
                } 
                cmd = (String[]) cmds.toArray(new String[cmds.size()]);
            }
            else
            if (args!=null)
            {
                ArrayList cmds = new ArrayList();
    
                // Add the base command...
                for (int i=0;i<base.length;i++) cmds.add(base[i]);
    
                for (int i=0;i<args.length;i++) 
                {
                    cmds.add(args[i]);
                } 
                cmd = (String[]) cmds.toArray(new String[cmds.size()]);
            }
            
            if (log.isBasic())
            {
                StringBuffer command = new StringBuffer();
                for (int i=0;i<cmd.length;i++)
                {
                    if (i>0) command.append(" ");
                    command.append(cmd[i]);
                }
                log.logBasic(toString(), "Executing command : "+command.toString());
            }
             
            // Launch the script!
            log.logDetailed(toString(), "Passing "+(cmd.length-1)+" arguments to command : ["+cmd[0]+"]");

            // Build the environment variable list...
            Runtime runtime = java.lang.Runtime.getRuntime();
            Process proc = runtime.exec(cmd,  
                    EnvUtil.getEnvironmentVariablesForRuntimeExec());
            
            // any error message?
            StreamLogger errorLogger = new
                StreamLogger(proc.getErrorStream(), toString()+" (stderr)");            
            
            // any output?
            StreamLogger outputLogger = new
                StreamLogger(proc.getInputStream(), toString()+" (stdout)");
                
            // kick them off
            new Thread(errorLogger).start();
            new Thread(outputLogger).start();
                                    
            proc.waitFor();
            log.logDetailed(toString(), "command ["+cmd[0]+"] has finished");
            
            // What's the exit status?
            result.setExitStatus( proc.exitValue() );
            if (result.getExitStatus()!=0) 
            {
                log.logDetailed(toString(), "Exit status of shell ["+getFileName()+"] was "+result.getExitStatus());
                result.setNrErrors(1);
            } 
        }
        catch(IOException ioe)
        {
            log.logError(toString(), "Error running shell ["+getFileName()+"] : "+ioe.toString());
            result.setNrErrors(1);
        }
        catch(InterruptedException ie)
        {
            log.logError(toString(), "Shell ["+getFileName()+"] was interupted : "+ie.toString());
            result.setNrErrors(1);
        }
        catch(Exception e)
        {
            log.logError(toString(), "Unexpected error running shell ["+getFileName()+"] : "+e.toString());
            result.setNrErrors(1);
        }
    

After Change


            
            if( Const.getOS().equals( "Windows 95" ) )
            {
                base = new String[] { "command.com", "/C", StringUtil.environmentSubstitute(getFileName()) };
            }
            else
            if( Const.getOS().startsWith( "Windows" ) )
            {
                base = new String[] { "cmd.exe", "/C", StringUtil.environmentSubstitute(getFileName()) };
            }
            else 
            {
                base = new String[] { StringUtil.environmentSubstitute(getFileName()) };
            }
    
            // Construct the arguments...
            if (argFromPrevious && cmdRows!=null)
            {
                ArrayList cmds = new ArrayList();
                
                // Add the base command...
                for (int i=0;i<base.length;i++) cmds.add(base[i]);
    
                // Add the arguments from previous results...
                for (int i=0;i<cmdRows.size();i++) // Normally just one row, but once in a while to remain compatible we have multiple. 
                {
                    Row r = (Row)cmdRows.get(i);
                    for (int j=0;j<r.size();j++)
                    {
                        cmds.add(r.getValue(j).getString());
                    }
                } 
                cmd = (String[]) cmds.toArray(new String[cmds.size()]);
            }
            else
            if (args!=null)
            {
                ArrayList cmds = new ArrayList();
    
                // Add the base command...
                for (int i=0;i<base.length;i++) cmds.add(base[i]);
    
                for (int i=0;i<args.length;i++) 
                {
                    cmds.add(args[i]);
                } 
                cmd = (String[]) cmds.toArray(new String[cmds.size()]);
            }
            
            if (log.isBasic())
            {
                StringBuffer command = new StringBuffer();
                for (int i=0;i<cmd.length;i++)
                {
                    if (i>0) command.append(" ");
                    command.append(cmd[i]);
                }
                log.logBasic(toString(), "Executing command : "+command.toString());
            }
             
            // Launch the script!
            log.logDetailed(toString(), "Passing "+(cmd.length-1)+" arguments to command : ["+cmd[0]+"]");

            // Build the environment variable list...
            Runtime runtime = java.lang.Runtime.getRuntime();
            Process proc = runtime.exec(cmd,  
                    EnvUtil.getEnvironmentVariablesForRuntimeExec());
            
            // any error message?
            StreamLogger errorLogger = new
                StreamLogger(proc.getErrorStream(), toString()+" (stderr)");            
            
            // any output?
            StreamLogger outputLogger = new
                StreamLogger(proc.getInputStream(), toString()+" (stdout)");
                
            // kick them off
            new Thread(errorLogger).start();
            new Thread(outputLogger).start();
                                    
            proc.waitFor();
            log.logDetailed(toString(), "command ["+cmd[0]+"] has finished");
            
            // What's the exit status?
            result.setExitStatus( proc.exitValue() );
            if (result.getExitStatus()!=0) 
            {
                log.logDetailed(toString(), "Exit status of shell ["+StringUtil.environmentSubstitute(getFileName())+"] was "+result.getExitStatus());
                result.setNrErrors(1);
            } 
        }
        catch(IOException ioe)
        {
            log.logError(toString(), "Error running shell ["+StringUtil.environmentSubstitute(getFileName())+"] : "+ioe.toString());
            result.setNrErrors(1);
        }
        catch(InterruptedException ie)
        {
            log.logError(toString(), "Shell ["+StringUtil.environmentSubstitute(getFileName())+"] was interupted : "+ie.toString());
            result.setNrErrors(1);
        }
        catch(Exception e)
        {
            log.logError(toString(), "Unexpected error running shell ["+StringUtil.environmentSubstitute(getFileName())+"] : "+e.toString());
            result.setNrErrors(1);
        }